﻿using System;
using System.Windows.Forms;
using Interfaces;
using Repository;

namespace Presenters
{
    public class ClientsModulePresenter
    {
        private IClientsView view = null;
        private Database db = null;
        private string exception = null;
        private string nameOperation = null;

        public ClientsModulePresenter(IClientsView view)
        {
            this.view = view;
            db = new Database();
            GetClientList();
        }

        private void RegisterView(IClientAddParent view)
        {
            Form view2 = view.ReturnView();
            view2.ShowDialog();
        }

        public void ShowFormView(IErrorView view)
        {
            view.nameOperation = "Dodanie klienta";
            view.exception = exception;
            view.ReturnView().ShowDialog();
        }

        /// <summary>
        /// Otwiera okno umożliwiające dodanie nowego obiektu typu Clients do bazy danych.
        /// </summary>
        public void ClientAddDisplay(IClientAddParent view)
        {
            RegisterView(view);
        }

        /// <summary>
        /// Zwraca listę wszystkich klientów w bazie danych
        /// </summary>
        public void GetClientList()
        {
            try
            {
                view.clientList = db.GetClientList();
            }
            catch(Exception ex)
            {
                exception = ex.Message;
                view.ShowError();
            }
        }
    }
}
